package es.cerosyunos.androiddevs;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;


public class TimedCapturesActivity extends Activity {
	
	private String mNumCap;
	private String mTimeCap;
	public final static String EXTRA_NUM_CAPS = "numCap";
	public final static String EXTRA_TIMER_CAPS = "timeCap";
	public final static int TAKE_CAPTIONS = 0;
	public final static int SHOW_CAPTIONS = 1;
	private ArrayList<String> imagenesCapturadas;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        imagenesCapturadas = new ArrayList<String>();
    }
    
    public void iniciaCapturas (View view){
    	Intent intent = new Intent(this, CameraCaptions.class);
    	EditText numCapturas = (EditText) findViewById(R.id.numeroCapturas);
    	EditText timeCapturas = (EditText) findViewById(R.id.tiempoCapturas);
    	mNumCap = numCapturas.getText().toString();
    	mTimeCap = timeCapturas.getText().toString();
    	intent.putExtra(EXTRA_NUM_CAPS, mNumCap);
    	intent.putExtra(EXTRA_TIMER_CAPS, mTimeCap);
    	startActivityForResult(intent,TAKE_CAPTIONS);
    }
    
    public void showCapturas (View view){
    	Intent intent = new Intent(TimedCapturesActivity.this, ShowCaptionsGallery.class);
    	Bundle bundle = new Bundle();
		bundle.putStringArrayList("IMGCAP", imagenesCapturadas);
		intent.putExtras(bundle);
    	startActivityForResult(intent,SHOW_CAPTIONS);
    }
    
    
    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) {     
    	super.onActivityResult(requestCode, resultCode, data); 
    	switch(requestCode) { 
    		case (TAKE_CAPTIONS) :  
    			if (resultCode == Activity.RESULT_OK) {
    				Button showButton = (Button) findViewById(R.id.muestraCaps);
    				showButton.setVisibility(View.VISIBLE);
    				Bundle extras = data.getExtras();
    				imagenesCapturadas = extras.getStringArrayList("IMGCAP");
    				Toast.makeText(this, "Captions finished", Toast.LENGTH_LONG).show();
    			} 
    			break;
    		case (SHOW_CAPTIONS) : 
    			if (resultCode == Activity.RESULT_OK) { 
    				setContentView(R.layout.main);
    			} 
    			break; 
    	} 
	}
    
}